package matrice;

import jeuDeLaVie.Cellule;

public class Bordure extends Matrice{

	private Matrice m;
	private int[] univers;
	
	public Bordure(Matrice m, int[] univers){		
		this.m=m;
		this.univers = univers;
	}



	@Override
	public boolean hasNext() {
		return m.hasNext();
	}

	@Override
	public Poid next() {
		Poid p = m.next();
		if(p.getCellule().getAbs()<univers[0]){
			p = new Poid(new Cellule(univers[1],p.getCellule().getOrd()),p.getNbVoisin());
		}else if(p.getCellule().getAbs()>univers[1]){
			p = new Poid(new Cellule(univers[0],p.getCellule().getOrd()),p.getNbVoisin());
		}else if(p.getCellule().getOrd()<univers[2]){
			p = new Poid(new Cellule(p.getCellule().getAbs(),univers[3]),p.getNbVoisin());
		}else if(p.getCellule().getOrd()>univers[3]){
			p = new Poid(new Cellule(p.getCellule().getAbs(),univers[2]),p.getNbVoisin());
		}else{
			if(this.hasNext()){
				return this.next();
			}else{
				return new Poid(new Cellule(univers[1]+1,univers[3]+1),0);
			}
		}
		return p;
	}
	
}
